//; mapshader.fx written by Alex Anderson
//; @15.8.12

// ################
// ### Varibles ###
float4x4 World;
float4x4 View;
float4x4 Projection;

float4 ZiColor;
float Timestamp;

float4 AmbientColor;
float AmbientLevel;

float3 DiffuseDirection;
float4 DiffuseColor;
float4 DiffuseLevel;

Texture ZiTexture;
sampler TextureSampler = sampler_state { texture = <ZiTexture> ; magfilter = LINEAR; minfilter = LINEAR; mipfilter=LINEAR; AddressU = mirror; AddressV = mirror;};


// #######################
// ### Data Structures ###
struct VertexData {
	float4 Position : POSITION;
	float2 UV : TEXCOORD0;
	float3 Normal : TEXCOORD1;
};

struct PixelData {
	float4 Color : COLOR0;
};

// ########################
// ### Shader Functions ###
VertexData ZiVertexShader(float4 inPos : POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords : TEXCOORD0)
{
	VertexData output = (VertexData)0;
	
	output.UV = inTexCoords;
	output.Normal = normalize(mul(inNormal, (float3x3)World));

	float4 position = mul(inPos, mul(World, mul(View, Projection))).xyzw;
	position.y += (0.2f * sin(Timestamp / 160));

	output.Position = position;

	return output;
}

PixelData ZiPixShader(VertexData inData)
{
	PixelData output = (PixelData)0;
	
	float4 texColor =tex2D(TextureSampler, inData.UV) * ZiColor ;
	texColor.a = (0.2f * sin(Timestamp / 160));

	float4 norm = float4(inData.Normal, 1.0);
	float4 diffuse = saturate(dot(-DiffuseDirection, norm));

	output.Color = 
		(texColor * (AmbientColor * AmbientLevel)) +
		(texColor * (DiffuseLevel * DiffuseColor * diffuse));

	//output.Color = texColor * (AmbientColor * AmbientLevel);

	return output;
}

// ##################
// ### Techniques ###
technique ZiShade
{
	pass Pass0
	{
		VertexShader = compile vs_2_0 ZiVertexShader();
		PixelShader = compile ps_2_0 ZiPixShader();
	}
}